<?php

	header('Content-type: text/html; charset=utf-8');
	if(!isset($_SESSION)){
		session_start();
	}

	$pdo = null;
	try {
	    $pdo = new PDO('sqlite:mydb1.db');
	    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	} catch (PDOException $e) {
	    die("连接失败: " . $e->getMessage());
	}


	if(isset($_GET['userInfo'])){
		$user_id = $_GET['userInfo'];
		$sql3 = "SELECT COUNT(1) AS souc FROM userDetail WHERE 
			uid = '$user_id' 
			AND  type1 = 'souc'";
		$arr1 = array();
		foreach($pdo->query($sql3)->fetchAll(PDO::FETCH_ASSOC) as $row){
			array_push($arr1, $row);
		}
		$sql4 = "SELECT COUNT(1) AS diny FROM userDetail WHERE 
			uid = '$user_id' 
			AND  type1 = 'diny'";
		foreach($pdo->query($sql4)->fetchAll(PDO::FETCH_ASSOC) as $row){
			array_push($arr1, $row);
		}
		// $obj1 = new stdClass(); // 初始化对象
		// $obj1->souc = $arr1[0].souc;
		// $obj1->diny = $arr1[1].diny;
		echo json_encode($arr1);	
		return;
	}
/*
SELECT COUNT(1) AS souc FROM userDetail WHERE 
	uid = 'C622E3D0-5585-4F6A-93F2-60766B550474' 
	AND  type1 = 'souc' 
*/

	if(isset($_GET['boFangList2'])){
		$user_id = $_GET['user_uId'];
		$id = $_GET['id'];
		$sql1 = "SELECT * FROM bokeWen WHERE id IN (
			 SELECT bokeId FROM userDetail WHERE 
			     uid = '$user_id'
			     AND type1 = 'bofa' ORDER BY id DESC LIMIT 2
			)
			ORDER BY id DESC LIMIT 2";
		$arr1 = array();
		foreach($pdo->query($sql1)->fetchAll(PDO::FETCH_ASSOC) as $row){
			array_push($arr1, $row);
		}
		echo json_encode($arr1);
		return;
	}
/*
SELECT * FROM bokeWen WHERE id IN (
 SELECT bokeId FROM userDetail WHERE 
     uid = 'C622E3D0-5585-4F6A-93F2-60766B550474'
     AND type1 = 'bofa' ORDER BY id DESC LIMIT 2
)
ORDER BY id DESC LIMIT 2
*/

	if(isset($_GET['shouCangList2'])){
		$user_id = $_GET['user_uId'];
		$id = $_GET['id'];
		$sql2 = "SELECT * FROM bokeWen WHERE id IN (
					 SELECT bokeId FROM userDetail WHERE 
					     uid = '$user_id'
					     AND type1 = 'souc'
				)
				ORDER BY id DESC LIMIT 2";
		$arr2 = array();
		foreach($pdo->query($sql2)->fetchAll(PDO::FETCH_ASSOC) as $row){
			array_push($arr2, $row);
		}
		echo json_encode($arr2);
		return; 
	}
/*
SELECT * FROM bokeWen WHERE id IN (
 SELECT bokeId FROM userDetail WHERE 
     uid = 'C622E3D0-5585-4F6A-93F2-60766B550474'
     AND type1 = 'souc'
)
ORDER BY id DESC LIMIT 2
*/




?>